/**
 * Formtils.js
 * 用于处理表单的工具类，使用post请求来避免乱码
 * author ： 赵远
 */

/**
 * formUrl : 请求地址
 * params : 参数
 * @param {type} formUrl
 * @param {type} params
 * @returns {undefined}
 */
window.FormUtils = function(formUrl, params) {
    this.formId;
    this.formUrl;
    this.params;
    this.requestUrl;
    this.setParams = function(formUrl, params) {
        this.params = params;
        this.formUrl = formUrl;
    };
    this.getFormHtmls = function() {
        var formId = "SubForm_" + Math.floor(Math.random() * 1000000);
        this.formId = formId;
        var forms = "<form id= '" + formId + "' name = '" + formId + "' action='" + formUrl + "' method='post'> ";
        for (var key in params) {
            var val = eval("params." + key);
            if (val == null || val == "null") {
                val = "";
            }
            forms += "<input type='hidden' name='" + key + "' value = '" + val + "'>";
        }
        forms += "</form>";
        $('body').append(forms);
    };
    this.getOpenHtmls = function() {
        var formUrl = this.formUrl;
        var params = this.params;
        var requestUrl = "";
        if (formUrl.indexOf("?") != -1) {
            formUrl += "&";

        } else {
            formUrl += "?";
        }
        if (params != null) {
            for (var key in params) {
                var val = eval("params." + key);
                if (val == null || val == "null") {
                    val = "";
                }
                requestUrl += "&" + key + " = '" + val + "'";
            }
            requestUrl = requestUrl.substr(1, requestUrl.lenth - 1);
            this.requestUrl = requestUrl;
        }
    };

    this.post = function() {

    };
    
    this.get = function (){
        
    };
    
    this.open = function(){
        
    };


    setParams(formUrl, params);
};




